package com.shujia.base.day03

import scala.collection.mutable
import scala.collection.mutable.ListBuffer

/**
 *  可变的集合【集合的原来基础上进行增删改】
 *
 *  可变的List集合：ListBuffer类似于java中ArrayList
 *  可变的Set集合：HashSet
 *  可变的Map集合：HashMap
 *  没有可变的元组
 */
object Demo21ListBuffer {
  def main(args: Array[String]): Unit = {
//    val list1:List[String] = List("hello", "world", "spark", "hello", "world", "flink")
//    list1.+=("scala")

    val listBuffer1:ListBuffer[String] = ListBuffer("hello", "world", "spark", "hello", "world", "flink")
    println(s"listBuffer1: ${listBuffer1}")
    listBuffer1.foreach(println)
    println("="*50)

    listBuffer1.+=("hbase") // 集合末尾处添加的一个元素
    println(s"listBuffer1: ${listBuffer1}")

    listBuffer1.-=("world") // 删除从左向右第一个符合的元素
    println(s"listBuffer1: ${listBuffer1}")

    listBuffer1.insert(1,"张成阳")
    println(s"listBuffer1: ${listBuffer1}")

    println("="*50)
    val hashSet1:mutable.HashSet[String] = mutable.HashSet("hello", "world", "spark", "hello", "world", "flink")
    println(s"hashSet1: ${hashSet1}")
    hashSet1.+=("hbase")
    println(s"hashSet1: ${hashSet1}")

    println("="*50)
    val map1: mutable.Map[Int, String] = mutable.HashMap(1001 -> "张三", 1002 -> "李四")
    println(s"map1:${map1}")
    map1.+=(1003->"王五")
    println(s"map1:${map1}")




  }
}
